<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<script type="text/javascript">
			//输入：version1 = "1.01", version2 = "1.001"
			//输出：0
			//解释：忽略前导零，"01" 和 "001" 都表示相同的整数 "1"

			//输入：version1 = "1.0", version2 = "1.0.0"
			//输出：0
			//解释：version1 没有指定下标为 2 的修订号，即视为 "0"

			//输入：version1 = "0.1", version2 = "1.1"
			//输出：-1
			//解释：version1 中下标为 0 的修订号是 "0"，version2 中下标为 0 的修订号是 "1" 。0 < 1，所以 version1 < version2

			/**
			 * @param {string} version1
			 * @param {string} version2
			 * @return {number}
			 */
			var compareVersion = function(version1, version2) {
				const v1 = version1.split('.');
				const v2 = version2.split('.');
				for (let i = 0; i < v1.length || i < v2.length; ++i) {
					let x = 0,
						y = 0;
					if (i < v1.length) {
						x = parseInt(v1[i]);
					}
					if (i < v2.length) {
						y = parseInt(v2[i]);
					}
					if (x > y) {
						return 1;
					}
					if (x < y) {
						return -1;
					}
				}
				return 0;
			};
			console.log(compareVersion("1.01", "1.001"));
			// console.log(compareVersion("1.0", "1.0.0"));
			// console.log(compareVersion("1.0.1", "1"));
		</script>
	</body>
</html>
